

import java.sql.*;
import java.awt.*;

import javax.swing.*;

import java.util.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class Initial extends JFrame {


    Connection conn = null;
    PreparedStatement ps = null;
    ResultSet res = null;
    Vector <Vector<String>>rowData = null;

    public Connection init() {
        try {
            String dbURL = "jdbc:sqlserver://localhost:1434;databasename=sy7"; // 1433是端口，"STUDB"是数据库名称
            String userName = "sa"; // 用户名
            String userPwd = "r123456"; // 密码
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            conn = DriverManager.getConnection(dbURL, userName, userPwd);
            System.out.println("数据库连接成功");
        }catch (Exception e){
            System.out.println("数据库连接失败");
        }
        return conn;
    }

    public Vector<Vector<String>> getStudent(Connection conn) {
        rowData = new Vector();
        try {
            ps = conn.prepareStatement("SELECT * FROM sc");
            res = ps.executeQuery();
            while (res.next())
            {
                Vector<String> hang = new Vector();
                hang.add(res.getString(1));
                hang.add(res.getString(2));
                hang.add(res.getString(3));
                hang.add(res.getString(4));
                rowData.add(hang);
            }
            System.out.println("load  ok!");
        }catch (Exception q){
            q.printStackTrace();
            System.out.println("go die");
        }
        return rowData;
    }


}
